import requests
import config.path_cnf as config


class GoodsAPI(object):

    def __init__(self):
        self.category_url = config.EGO_URL + config.CATEGORY_URL
        self.prod_by_category_url = config.EGO_URL + config.PROD_BY_CATEGORY_URL
        self.product_info_url = config.EGO_URL + config.PROD_INFO_URL

    # 获取商品分类
    def get_category(self):
        return requests.get(self.category_url)

    # 获取商品分类下的商品(查询参数 id=)
    def get_prod_by_category(self, id):
        return requests.get(self.prod_by_category_url, params={'id': str(id)})

    # 获取商品信息
    def get_product_info(self, path_params):
        return requests.get(self.product_info_url + str(path_params))


if __name__ == '__main__':
    # 获取商品分类
    print(GoodsAPI().get_category())

    # 获取商品分类下的商品
    print(GoodsAPI().get_prod_by_category('3'))

    # 获取商品信息
    print(GoodsAPI().get_product_info('2'))

